package main

import "fmt"

/*
练习4：验证用户名密码是否正确
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"158xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}
	输入用户名密码，进行验证，验证成功后，输出手机号码
*/

func main()  {
	var userList = map[string]map[string]string{
		"root":{"password":"123456", "tel":"158xxxxxxxx"},
		"admin":{"password":"123456", "tel":"158xxxxxxxx"},
		"xiaoming":{"password":"123456", "tel":"158xxxxxxxx"}}

	var user string
	var passwd string
	var flag int
	count := 0

	for true{
		// 无限循环的代码块
		fmt.Printf("请输入用户名:")
		fmt.Scan(&user)
		//fmt.Println(user)
		for username,userinfo := range userList{
			if user != username {
				count ++
			} else {
				fmt.Printf("请输入密码:")
				fmt.Scan(&passwd)
				if passwd == userinfo["password"] {
					fmt.Printf("验证成功，手机号为：%s",userinfo["tel"])
					flag = 1
					break
				} else {
					fmt.Printf("密码错误")
					break
				}
			}
			if count == 3 {
				fmt.Printf("用户名输入错误，请重新输入")
			}
		}
		fmt.Println()
		if flag == 1{
			break
		}
	}
}












